﻿namespace Tsari.Mes.Plc.Extensions
{
    public static class ConfigurationExtensions
    {
        public static PlcTypeOption GetPlcTypeOption(this IConfiguration configuration)
        {
            var options = configuration.GetOptions<PlcTypeOption>("plc", (conf, Key) =>
            {
                IConfigurationSection section = configuration.GetSection(Key);
                if (!section.Exists())
                {
                    throw new MicroCloudException("Province配置选项不存在，请在appsetting.json配置 Province 节点");
                }
                var plcTypeOption = new PlcTypeOption();
                plcTypeOption.Dicts = section.Get<Dictionary<string, PlcTypeData[]>>();

                return plcTypeOption;
            });

            return options;
        }
    }
}
